local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.BaseComponent());
local CommonOHOH = _G.CommonOHOH;
local BigNumberHelper = CommonOHOH.load.BigNumberHelper();
local Assetcfg = ServerOHOH.config.Asset;

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.topUi=ServerOHOH:GetPath_Loop("TopUI",game.ReplicatedStorage.Resource.UI):Clone()
    local att=Instance.new("Attachment",self.parent.main_inst:WaitForChild("Head"))
    att.CFrame=self.topUi:WaitForChild("pos").Value
    self.topUi.Parent=att
    self.DataBase=self.parent.player:GetComponent(ServerOHOH.load.Server_PlayerDataComponent());
    self.PowerLable=self.topUi:WaitForChild("Frame"):WaitForChild("Strength"):WaitForChild("TextLabel")
    self.topUi:WaitForChild("Frame"):WaitForChild("Strength"):WaitForChild("ImageLabel").Image=Assetcfg.base_power.rid
    
    self.RebirthLable=self.topUi:WaitForChild("Frame"):WaitForChild("Rebirth"):WaitForChild("TextLabel")
    self.LevelLable=self.topUi:WaitForChild("Frame"):WaitForChild("Rebirth"):WaitForChild("LV")
    local p=math.floor(self.DataBase:GetData("base").power+0.5)
    self.PowerLable.Text=BigNumberHelper:ToString(p) 
    self.RebirthLable.Text=self.DataBase:GetData("base").rebirth
    self.LevelLable.Text="Lv."..self.DataBase:GetData("base").level

    self.parent.player.UserDataEvent:Connect(function(key)
        if key=="base"  then
            local p=math.floor(self.DataBase:GetData("base").power+0.5)
            self.PowerLable.Text=BigNumberHelper:ToString(p) 
            self.RebirthLable.Text=self.DataBase:GetData("base").rebirth
            self.LevelLable.Text="Lv."..self.DataBase:GetData("base").level
        end
    end)
end;

function M.dtor(self)
    -- print("Server_TopUiCtrl--dtor----Server")

	M.super.dtor(self);
end;

return M